
capture log close

set more off
set matsize 10000


use rep_final, clear

	*noncitizens
	keep if cit==0
	*married last year, currently still married with spouse present
	keep if marrinyr==2 & married==1 
	*spouse info is avail.
	drop if citizen_sp==.

* Define control variables 

	local demog "age age2 male yreduc i.racegr"
	local imm "ysm i.bpl " 
	local fe "i.statefip i.yrmarr "
	
	local full "`demog' `imm' `fe' "

* Use yrmarr to measure time treatment because individuals are surveyed throughout the year

	g post1=(yrmarr>=2013 & yrmarr<=2016)
	g post2=(yrmarr>=2017)
	
	g treatpost1=treatgr*post1
	g treatpost2=treatgr*post2
	
*******************************************************************************
*Table 3, Panel A

	*by gender
	
		local a=1
	foreach gender of varlist female male {
	
		foreach controlgr of varlist controlgrdaca  {

		foreach depvar of varlist cit_sp  {
	
			
			display ""
			display "--------------------------------------"
			
			display "Dependent Variable: `depvar' "
			display "Contorl Group: `controlgr' "
			display "Gender: `gender' "
			
			
			display "--------------------------------------"
			

			*note treatpost1 and treatpost2 both compare to pre-period.

			
			reg `depvar' treatpost1 treatpost2 treatgr `full'  ///
				if (daca==1|`controlgr'==1) & `gender'==1   [pweight = perwt] , cluster(statefip)
			est sto e`a'	
			
			local a=`a'+1
			
		*dep var mean
	
		sum cit_sp [fweight=perwt] if e(sample) 
				}
				
		

			}

		}			
		
		*make table
			esttab e1 e2 ///
					using table3_panelA.csv, se  ///
					mtitles("Female" ///
							"Male" ) ///
					title(Intermarriage Rate) ///
					b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) ///
					nogaps replace			
		
	
**************************************************************************
*Table 3 - Panel B
	*by endogamy and exogamy
	
	*redefine by race and ethnicity
		
		g racegr1=1 if hispanic == 1 & race==1
			replace racegr1 = 2 if hispanic == 1 & race == 2 
			replace racegr1 = 3 if hispanic ==1 & (race==4|race==5|race==6) 
			replace racegr1 = 4 if hispanic ==1 & ///
									(race~=1 & race~=2 & race~=4 & race~=5 & race~=6)
			replace racegr1 = 5 if hispanic == 0 & race==1
			replace racegr1 = 6 if hispanic == 0 & race == 2 
			replace racegr1 = 7 if hispanic == 0 & (race==4|race==5|race==6) 
			replace racegr1 = 8 if hispanic == 0 & ///
									(race~=1 & race~=2 & race~=4 & race~=5 & race~=6)
				   
		label define racegr1lbl   1 "Hispanic white" ///
								  2 "Hispanic black" ///
								  3 "Hispanic Asian" ///
								  4 "Hispanic Otherrace" ///
								  5 "Non-Hisp white" ///
								  6 "Non-Hisp black" ///
								  7 "Non-Hisp Asian" ///
								  8 "Non-Hisp Otherrace"
								  
		label values racegr1 racegr1lbl

		* spouse race
		
		g racegr1_sp=1 if hispanic_sp == 1 & race_sp==1
			replace racegr1_sp = 2 if hispanic_sp == 1 & race_sp == 2 
			replace racegr1_sp = 3 if hispanic_sp ==1 & ///
										(race_sp==4|race_sp==5|race_sp==6) 
			replace racegr1_sp = 4 if hispanic_sp ==1 & ///
									(race_sp~=1 & race_sp~=2 & race_sp~=4 & race_sp~=5 & race_sp~=6)
			replace racegr1_sp = 5 if hispanic_sp == 0 & race_sp==1
			replace racegr1_sp = 6 if hispanic_sp == 0 & race_sp == 2 
			replace racegr1_sp = 7 if hispanic_sp == 0 & ///
										(race_sp==4|race_sp==5|race_sp==6) 
			replace racegr1_sp = 8 if hispanic_sp == 0 & ///
									(race_sp~=1 & race_sp~=2 & race_sp~=4 & race_sp~=5 & race_sp~=6)
				   
		label define racegr1_splbl 	  1 "Hispanic white" ///
									  2 "Hispanic black" ///
									  3 "Hispanic Asian" ///
									  4 "Hispanic Otherrace" ///
									  5 "Non-Hisp white" ///
									  6 "Non-Hisp black" ///
									  7 "Non-Hisp Asian" ///
									  8 "Non-Hisp Otherrace"
								  
		label values racegr1_sp racegr1_splbl

	* measure endogamous/exogamous intermarriages, note noncitizen spouse is always in the base.

	g samerace_nativesp=(racegr1==racegr1_sp & native_sp==1)
	
	g samerace_citimmsp=(racegr1==racegr1_sp & citimm_sp==1)
	
	g diffrace_nativesp=(racegr1~=racegr1_sp & native_sp==1)
	
	g diffrace_citimmsp=(racegr1~=racegr1_sp & citimm_sp==1)
	
	
	* generate endogamy vs exogamy	
	g samerace=(samerace_nativesp==1|samerace_citimmsp==1)
	g diffrace=(diffrace_nativesp==1|diffrace_citimmsp==1)
	
	
	foreach controlgr of varlist controlgrdaca  {
		local a=1
		foreach depvar of varlist samerace diffrace {
	
			
			display ""
			display "--------------------------------------"
			
			display "Dependent Variable: `depvar' "
			display "Control group: `controlgr' "

			display "--------------------------------------"
			

			*treatpost1 and treatpost2 both compare to pre-period.

			reg `depvar' treatpost1 treatpost2 treatgr `full'  ///
				if (daca==1|`controlgr'==1)   [pweight = perwt] , cluster(statefip)
			est sto e`a'	

			local a=`a'+1
			
		*dep var mean
	
		sum samerace diffrace [fweight=perwt] if e(sample) 
		
			}
		}
			*Make table 
			esttab e1 e2  ///
					using table3_panelB.csv, se  ///
					mtitles("Married to a Same Race and Ethnicity Citizen "  ///
							"Married to a Different Race/Ethnicity Citizen" )   ///
					title(Intermarriage Rate) ///
					b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) ///
					nogaps replace

*********************************************************************************
*Table 3 - Panel C

*Top 10 states with largest Hisp population:
*California-6, Texas-48, Florida-12, New York-36, Illinois-17, Arizona-4
*New Jersey-34, Colorado-8, New Mexico-35, Georgia-13

	g hispst=1 if statefip==6  | ///
					 statefip==48 | ///
					 statefip==12 | ///
					 statefip==36 | ///
					 statefip==17 | ///
					 statefip==4 | ///
					 statefip==34 | ///
					 statefip==8 | ///
					 statefip==35 | ///
					 statefip==13 
		replace hispst=0 if hispst==.

	
	foreach sthetero of varlist hispst {
	foreach controlgr of varlist controlgrdaca  {
		foreach depvar of varlist cit_sp  {
	
			
			display ""
			display "--------------------------------------"
			
			display "Dependent Variable: `depvar' "
			
			display "--------------------------------------"
		

			*treatpost1 and treatpost2 both compare to pre-period
			
			
			reg `depvar' treatpost1 treatpost2 treatgr `full'  ///
				if (daca==1|`controlgr'==1) & `sthetero'==1  [pweight = perwt] , cluster(statefip)
			est sto e1	
			
				*dep var mean
				sum cit_sp  [fweight=perwt] if e(sample) 

			reg `depvar' treatpost1 treatpost2 treatgr `full'  ///
				if (daca==1|`controlgr'==1) & `sthetero'==0  [pweight = perwt] , cluster(statefip)
			est sto e2
				
				*dep var mean
				sum cit_sp  [fweight=perwt] if e(sample) 

			}
		
			*Make table 
			
			esttab e1 e2  ///
					using table3_panelC.csv, se  ///
					title(Intermarriage Rate) ///
					b(%9.4f) se(%9.4f) star(* 0.1 ** 0.05 *** 0.01) ///
					nogaps replace			
			
		}
}
